package consulTest.service;

import consulTest.Entity.TestEntity;
import consulTest.dao.EventLogDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * Created by lipor
 * Date 2020/9/8
 */
@Service
public class TestEntityService {

    @Autowired
    private EventLogDAO eventLogDAO;

    @Cacheable(cacheNames = "testEntity", key = "'entity:'+#id", condition = "#id>5", unless = "#id>3")

    public TestEntity findById(Integer id) {
        TestEntity entity = eventLogDAO.test8(id);
        System.out.println("查询数据库拉");
        return entity;
    }

    @CachePut(cacheNames = "testEntity")
    public TestEntity findByIdPut(Integer id) {
        TestEntity entity = eventLogDAO.test8(id);
        System.out.println("查询数据库拉put");
        return entity;
    }

    @CacheEvict(value = "clear", allEntries = true)
    public String clear() {
        return "清空Redis拉";
    }

    public void addEntity(TestEntity testEntity) {
        eventLogDAO.addEntity(testEntity);
    }

    public Boolean testboolean(int id) {

        System.out.println(eventLogDAO.isDebitEnabled(id));

        return eventLogDAO.isDebitEnabled(id);
    }

}
